package com.adingxiong.quickstart.config;

import liquibase.integration.spring.SpringLiquibase;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

/**
 * @ClassName LiqiubaseConfig
 * @Description    liquibase 配置文件   自动生成数据表
 * @Author xiongchao
 * @Date 2020/5/21 16:37
 **/

@Configuration
public class LiqiubaseConfig {

    @Value("${spring.liquibase.change-log}")
    private  String logPath;
    @Value("${spring.liquibase.contexts}")
    private String contexts;

    private Logger logger = LoggerFactory.getLogger(LiqiubaseConfig.class);
    @Bean
    public SpringLiquibase liquibase(DataSource dataSource) {
        logger.warn("================" + logPath);
        logger.warn(contexts);
        SpringLiquibase liquibase = new SpringLiquibase();
        liquibase.setDataSource(dataSource);
        //指定changelog的位置，这里使用的一个master文件引用其他文件的方式
        liquibase.setChangeLog(logPath);
        liquibase.setContexts(contexts);
        liquibase.setShouldRun(true);
        return liquibase;
    }
}
